//
//  InformationViewController.m
//  GuoBuGaForIphone
//
//  Created by zhangwo on 16/10/26.
//  Copyright © 2016年 GuoBuGa. All rights reserved.
//

#import "InformationViewController.h"

@interface InformationViewController ()
{
    NSInteger index;
}

@end

@implementation InformationViewController
@synthesize tableView = _tableView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"消息"];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"发布消息" style:UIBarButtonItemStyleBordered target:self action:@selector(releaseButton)];
    self.navigationItem.rightBarButtonItem = rightBarItem;
    
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
    
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"titleCell"];

//    UIView *bgview = [[UIView alloc] initWithFrame:CGRectMake(10, 10, SWIDTH-20, 40)];
//    CGRect backfram = bgview.bounds;
//    bgview.backgroundColor = [UIColor colorWithHexString:@"0xDCDCDC"];
//    bgview.layer.cornerRadius = 8;
    
//    NSArray *titleArray = @[@"群通知",@"个人消息"];
//    index = 0;
//    for(int i =0 ;i<2;i++)
//    {
//        UIButton *segBtn = [[UIButton alloc] initWithFrame:CGRectMake(i*backfram.size.width/2, 0, backfram.size.width/2, 40)];
//        segBtn.tag = i+1;
//        [segBtn setTitle:titleArray[i] forState:UIControlStateNormal];
//        segBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
//        segBtn.userInteractionEnabled = YES;
//        [segBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        
//        if(index==i)
//        {
//            [segBtn setBackgroundColor:[UIColor colorWithHexString:@"0x1A93F3"]];
//            CAShapeLayer *maskLayer = [CAShapeLayer layer];
//             maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:segBtn.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii: (CGSize){10.0f, 10.0f}].CGPath;
//            segBtn.layer.mask = maskLayer;
//            
//            [segBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        }else
//        {
//            [segBtn setBackgroundColor:[UIColor clearColor]];
//            CAShapeLayer *maskLayer = [CAShapeLayer layer];
//            maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:segBtn.bounds byRoundingCorners: UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii: (CGSize){10.0f, 10.0f}].CGPath;
//            segBtn.layer.mask = maskLayer;
//            
//            [segBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        }
//        [segBtn addTarget:self action:@selector(chargeButton:) forControlEvents:UIControlEventTouchUpInside];
//        [bgview addSubview:segBtn];
//    }
    
    NSArray *segmentedData = [[NSArray alloc] initWithObjects:@"群消息",@"个人消息", nil];
    UISegmentedControl *segmentedButton = [[UISegmentedControl alloc] initWithItems:segmentedData];
    segmentedButton.frame = CGRectMake(10, 10,SWIDTH-20, 40);
    segmentedButton.layer.cornerRadius = 10;
    segmentedButton.backgroundColor = [UIColor colorWithHexString:@"0xDCDCDC"];
    segmentedButton.layer.borderColor = [[UIColor colorWithHexString:@"0xDCDCDC"] CGColor];
    segmentedButton.layer.borderWidth = 1;

     //这个是设置按下按钮时的颜色
    segmentedButton.tintColor = [UIColor colorWithHexString:@"0x1493F9"];
    segmentedButton.selectedSegmentIndex = 0;//默认选中的按钮索引
    
     //下面的代码实同正常状态和按下状态的属性控制,比如字体的大小和颜色等
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName,[UIColor blackColor], NSForegroundColorAttributeName, nil];
    [segmentedButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
     segmentedButton.apportionsSegmentWidthsByContent = NO;
    
    //选中时字体颜色
    NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    [segmentedButton setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
    //设置分段控件点击相应事件
    [segmentedButton addTarget:self action:@selector(doSomethingInSegment:)forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:segmentedButton];
    [self newNoticeView];
}

//- (void)chargeButton:(UIButton *)button
//{
//    for (int i = 0; i<2; i++) {
//        //得到上一次选中的btn 并修改颜色
//        UIButton *currBtn = (UIButton *)[self.view viewWithTag:i+1];
//        if (button.tag -1 == i) {
//            [currBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//            CAShapeLayer *maskLayer = [CAShapeLayer layer];
//            maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:currBtn.bounds byRoundingCorners: UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii: (CGSize){10.0f, 10.0f}].CGPath;
//            currBtn.layer.mask = maskLayer;
//            [currBtn setBackgroundColor:[UIColor colorWithHexString:@"0x1A93F3"]];
//        }
//        else
//        {
//            //修改当前选中的颜色
//            [currBtn setBackgroundColor:[UIColor colorWithHexString:@"0xDCDCDC"]];
//            
//            [currBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//            CAShapeLayer *maskLayer = [CAShapeLayer layer];
//            maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:currBtn.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii: (CGSize){10.0f, 10.0f}].CGPath;
//            currBtn.layer.mask = maskLayer;
////            currBtn.layer.cornerRadius = 10;
//            
//            [currBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        }
//    }
//    
//    //当前选中的下标
//    index = button.tag -1;
//    switch (index) {
//        case 0:
//            [self newNoticeView];
//            break;
//            
//        default:
//            [self MyInformationView];
//            break;
//    }
//}

-(void)doSomethingInSegment:(UISegmentedControl *)Seg
{
    NSInteger Index = Seg.selectedSegmentIndex;
    switch (Index)
    {
        case 0:
            [self newNoticeView];
            break;
        case 1:
            [self MyInformationView];
            break;
        default:
            break;
    }
}

- (void)newNoticeView
{
    if (!_newNotice) {
        _newNotice = [[NoticeView alloc]initWithFrame:CGRectMake(0, 60, SWIDTH, SHEIGHT)];
    }
    [self.view addSubview:_newNotice];
}

- (void)MyInformationView
{
    if (!_myInformation) {
        _myInformation = [[MyInformationView alloc] initWithFrame:CGRectMake(0, 60, SWIDTH, SHEIGHT)];
        _myInformation.delegate = self;
    }
    [self.view addSubview:_myInformation];
}

///发布消息
- (void)releaseButton
{
    SendMessageViewController *sendMessge = [[SendMessageViewController alloc] init];
    [self.navigationController pushViewController:sendMessge animated:YES];
}

//详情
- (void)selectInformationId:(NSString *)informationId
{
    InforDetailsViewController *detailsView = [[InforDetailsViewController alloc] init];
    [self.navigationController pushViewController:detailsView animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return SHEIGHT;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"titleCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    _tableView.separatorStyle = NO;//隐藏tableViewCell的线条
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
